//
//  Component.swift
//  ClockWidget
//
//  Created by TSYH on 2023/10/7.
//

import UIKit

public protocol Component {}

public protocol ComponentView {
    // UI 渲染
    func renderView(with object: Any?, component: CollectionViewComponent, attributes: [String: Any]?)
}

public protocol CollectionViewSectionComponent: Component {
    var cells: [CollectionViewCellComponent] { get }
    var headerComponent: CollectionViewReuseViewComponent? { get }
    var footerComponent: CollectionViewReuseViewComponent? { get }
    var sectionInset: UIEdgeInsets { get }
    var lineSpacing: CGFloat { get }
    var itemSpacing: CGFloat { get }
    
    func append(_ childrens: [Component])
}

public extension CollectionViewSectionComponent {
    var headerComponent: CollectionViewReuseViewComponent? { return nil }
    var footerComponent: CollectionViewReuseViewComponent? { return nil }
    
    var sectionInset: UIEdgeInsets {
        return UIEdgeInsets(top: 10, left: 16, bottom: 10, right: 16)
    }
    
    var lineSpacing: CGFloat {
        return 12.0
    }
    
    var itemSpacing: CGFloat {
        return 12.0
    }
}

public enum CollectionViewReuseViewType {
    case header
    case footer
}

public protocol CollectionViewReuseViewComponent: Component {
    var viewClass: UICollectionReusableView.Type { get }
    var viewType: CollectionViewReuseViewType { get }
    var viewSize: CGSize { get }
}

public protocol CollectionViewCellComponent: Component {
    var cellClass: UICollectionViewCell.Type { get }
    
    // 新增 rect: UICollectionView.frame
    func cellSize(with attrubites: [String: Any]?, in rect: CGRect) -> CGSize
}

public protocol CollectionViewCellSwipeComponent {
    var swipeActions: [SwipeAction]? { get }
}
